const app = getApp()
const $api = require('../../../utils/api.js').API;

Page({
    data: {
        submittrue:true,
        form:{
          'city':'天津市-天津市-和平区',
          'type':1
        },
        citytext:'天津市',
        region: ['天津市', '天津市', '全部'],
        str:'',
        num:''
    },
    onLoad: function(e){
        this.setData({
          str:e.str,
          num:e.num
        })
    },
    companyAdd:function(){
      var that = this
      var arr = {'name':'收货人不能为空',
            'phone':'联系电话不能为空',
            'city':'所在城市不能为空',
            'address':'具体地址不能为空'}
      for(var x in arr){
        if(!this.data.form[x]){
          wx.showToast({
            title:arr[x],
            duration:3000,//显示时长
            mask:true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon:'none', //图标，支持"success"、"loading" 
          })
          return;
        }
      }
      var form = this.data.form
      form.uid = wx.getStorageSync('uid')
      $api.post('address/add',form).then(res => {
        //请求成功
        if(res.data.code == 1){
          this.setData({
            submittrue:false
          })
          wx.showToast({
            title:'添加成功!!!',
            duration:3000,//显示时长
            mask:true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon:'none', //图标，支持"success"、"loading" 
            success:function(){
              setTimeout(function(){
                wx.navigateTo({
                    url:'/pages/pointsMall/order?str='+that.data.str+'&num='+that.data.num
                })
              },3000) //延迟时间 这里是
            }
          })
        }else{
          wx.showToast({
            title:'添加失败',
            duration:3000,//显示时长
            mask:true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon:'none', //图标，支持"success"、"loading" 
          })
          return;
        }
    }).catch(err => {
        //请求失败
        //console.log('error',err);
    })
    },
    bindKeyInput:function(e){
      var form = this.data.form
      var name = e.target.dataset.name
      var value = e.detail.value
      form[name] = value
      this.setData({
        form:form
      })
    },
    bindRegionChange: function (e) {
      var region = e.detail.value
      var form =  this.data.form
      form['city'] = region[0] + '-' + region[1] + '-' + region[2]
      this.setData({
        region:region,
        form: form
    })
  },
  bindRadio:function(e){
    var form = this.data.form
    form['type'] = e.detail.value
    this.setData({
      form:form
    })
  },
onShareAppMessage: function() {
  return {
      title: "天意美业直通车",
      path: "/pages/index/index?puid="+wx.getStorageSync('uid')
  };
}
});